<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
  <title>会员列表</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../LayUi/plugin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../LayUi/css/style.css">
  <script type="text/javascript" src="../LayUi/js/jquery.min.js"></script>
  <script type="text/javascript" src="../LayUi/plugin/layui/layui.js"></script>
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="border-radius: 0;border-top: 4px solid #d2d2d2;">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">项目编号</label>
          <div class="layui-input-inline">
            <input type="text" id="projectId" name="项目编号" placeholder="请输入项目编号" autocomplete="off" class="layui-input">
          </div>
            <label class="layui-form-label">项目名称</label>
            <div class="layui-input-inline">
              <input type="text" id="projectName" name="项目编号" placeholder="请输入项目名称" autocomplete="off" class="layui-input">
            </div>
              <label class="layui-form-label">电缆名称</label>
              <div class="layui-input-inline">
                <input type="text" id="cableName" name="项目编号" placeholder="请输入电缆名称" autocomplete="off" class="layui-input">
          </div>
          <label class="layui-form-label">完成状态</label>
          <div class="layui-input-inline">
            <input type="text" id="planStatus" name="项目编号" placeholder="请输入完成状态" autocomplete="off" class="layui-input">
          </div>
        </div>
        </div>

    <div class="layui-card-body">

      <div style="padding-bottom: 10px;">
        <button id="btnSearch" class="layui-btn layuiadmin-btn-useradmin layui-bg-blue">查询</button>
        <button class="layui-btn layuiadmin-btn-useradmin layui-bg-blue" data-type="add">重置</button>
        <button class="layui-btn layuiadmin-btn-useradmin layui-bg-blue" data-type="add">新建</button>
        <button class="layui-btn layuiadmin-btn-useradmin layui-bg-blue" data-type="add">导入</button>
        <button class="layui-btn layuiadmin-btn-useradmin layui-bg-blue" data-type="add">导出反馈汇总</button>
        <button class="layui-btn layuiadmin-btn-useradmin layui-bg-blue" data-type="add">今日派单</button>
        <button class="layui-btn layuiadmin-btn-useradmin layui-bg-blue" data-type="add">合并派单</button>
        <button class="layui-btn layuiadmin-btn-useradmin layui-bg-blue" data-type="add">合并完单</button>
        <button class="layui-btn layuiadmin-btn-useradmin layui-bg-blue" data-type="add">派单记录</button>
        <button class="layui-btn layuiadmin-btn-useradmin layui-bg-blue" data-type="add">完单记录</button>
      </div>

      <!--  表格数据加载 -->
      <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>



      <script type="text/html" id="table-useradmin-webuser">
        <!-- 修改 -->
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <!-- 删除 -->
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
        <!-- 查询 -->
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="query"><i class="layui-icon layui-icon-delete"></i>详情</a>
      </script>

      <!--状态判断-->
      <script type="text/html" id="statusTpl">
        {{#  if(d.status == 1){ }}
        <button class="layui-btn layui-btn-xs">正常</button>
        {{#  } else if(d.status == 2) { }}
        <button class="layui-btn layui-btn-primary layui-btn-xs">冻结</button>
        {{#  } }}
      </script>

      <script type="text/html" id="sexTpl">
        {{#  if(d.sex == 1){ }}
        <span>男</span>
        {{#  } else if(d.sex == 2) { }}
        <span>女</span>
        {{#  } }}
      </script>

      <!--  创建时间格式化处理 -->
      <script type="text/html" id="createTimeTpl">
        {{formatDate(d.createTime)}}
      </script>

      <!--  更新时间格式化处理 -->
      <script type="text/html" id="updateTimeTpl">
        {{formatDate(d.updateTime)}}
      </script>

    </div>
  </div>
</div>

<script src="../../../layui/layui.js"></script>
<script type="text/javascript">
  // 日期格式转换函数
  function formatDate(str) {
    if(str != null){
      var now = new Date(str);
      var year = now.getFullYear();  //取得4位数的年份
      var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
      var date = now.getDate();      //返回日期月份中的天数（1到31）
      var hours = now.getHours();
      var minutes = now.getMinutes();
      var seconds = now.getSeconds();
      return year + "-" + month + "-" + date +" "+hours+":"+minutes+":"+seconds;
    }
    return "";
  }
</script>
<script type="text/javascript">
  layui.config({
    base: '../../../layui/layuiAdmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['layer','table','form'], function(){
    var $ = layui.$
            ,form = layui.form
            ,layer = layui.layer
            ,table = layui.table;

    //加载table
    table.render({
      elem: '#LAY-user-manage'
      ,url:'/logistics_cablePlan/list' //后端接口
      ,cellMinWidth: 80 //全局定义常规单元格的最小宽度
      ,title: '系统用户数据表'
      ,cols: [[
        {type: 'checkbox', fixed: 'left'}
        ,{field:'projectId',title:'项目编号',width:100}
        ,{field:'projectName', title:'项目名称',width:90}
        ,{field:'cableName', title:'电缆名称',width:90}
        ,{field:'voltageName', title:'电压等级',width:90}
        ,{field:'extractionLength;', title:'电缆截面',width:90}
        ,{field:'extractionDate', title:'抽取日期',width:180}
        ,{field:'receivingStatus', title:'入库状态',width:90}
        ,{field:'receivingNumber', title:'入库数量',width:90}
        ,{field:'shippingStatus', title:'出库状态',width:90}
        ,{field:'shippingNumber', title:'出库数量',width:90,templet:'#statusTpl'}
        ,{field:'dispatchStatus', title:'派单状态',width:90,templet: '#createTimeTpl'}
        ,{field:'planStatus', title:'计划状态',width:190}
        ,{fixed: 'right', title:'操作',toolbar: '#table-useradmin-webuser',width:280,}

      ]]

      ,page: {
        curr: 1 //设定初始在第 5 页
        ,limit: 5 //设定初始每页显示 5 条
      },
      limits:[5,10,15,20]
    });

    //监听行工具事件
    table.on('tool(LAY-user-manage)', function(obj){
      var data = obj.data;
      if(obj.event === 'del'){
        layer.confirm('真的删除行么', function(index){
          $.ajax({
            url:"/logistics_cablePlan", //请求后端接口地址
            type:"post", //请求方式get | post
            data:{id:data.id}, //提交json字符串对象参数
            dataType:"json", //后端返回参数类型
            success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
              if(res.code == 0){//成功
                layer.msg(res.message);//弹出提示
                table.reload('LAY-user-manage'); //数据刷新
                layer.close(index); //关闭弹层
              }else {
                layer.msg(res.message,{icon: 5});//弹出提示
              }
            }
          })
        });
      } else if(obj.event === 'edit'){
        layer.open({
          type: 2
          ,title: '修改电缆计划'
          ,skin: 'layui-layer-win10'
          ,content: 'edit.html'
          ,maxmin: true
          ,area: ['480px', '550px']
          ,btn: ['确定', '取消']
          ,success: function (layero,index){ //弹出层加载之前执行
            // 获取选中行的数据
            // 获取弹出层的表单
            var body = layer.getChildFrame("body",index);
            var contentWindow = layero.find('iframe')[0].contentWindow;//得到iframe页的窗口对象，执行iframe页的方法：
            iframeWin.method();
            // 获取编辑表单中用户名元素
            // 数据回显到弹出的表单中
            contentWindow.layui.form.val('layuiadmin-form-useradmin', {
              "id": data.id,
              "projectId":data.projectId,
              "projectName":data.projectName,
              "cableName":data.cableName,
              "voltageName":data.voltageName,
              "extractionLength":data.extractionLength,
              "extractionDate":data.extractionDate,
              "receivingStatus":data.receivingStatus,
              "receivingNumber":data.receivingNumber,
              "shippingStatus":data.shippingStatus,
              "shippingNumber":data.shippingNumber,
              "dispatchStatus":data.dispatchStatus,
              "planStatus":data.planStatus
            });

          }
          ,yes: function (index,layero){
            var iframeWindow = window['layui-layer-iframe'+ index]
                    ,submitID = 'LAY-user-front-submit'
                    ,submit = layero.find('iframe').contents().find('#'+ submitID);
            //监听提交--隐藏按钮
            iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
              var field = data.field; //获取提交的字段
              // 通过Ajax方式将参数提交到后端--保存数据库中
              $.ajax({
                url:"/logistics_cablePlan/{id}",
                type:"post",
                data:JSON.stringify(field),
                contentType: "application/json;charset=utf-8", //提交参数类型为json格式
                dataType:"json",
                success:function (res){
                  if(res.code == 0){//成功
                    layer.msg(res.message);//弹出提示
                    table.reload('LAY-user-manage'); //数据刷新
                    layer.close(index); //关闭弹层
                  }else{//系统出问题
                    layer.msg(res.message,{icon: 5});//弹出提示
                  }
                }
              })
            });
            submit.trigger('click');
          }
        });


      }
    });


// 监听查询按钮点击事件
$('#btnSearch').on('click', function() {
  var projectId = $('#projectId').val(); // 获取输入框的值
  var projectName = $('#projectName').val();
  var cableName = $('#cableName').val();
  var planStatus = $('#planStatus').val();
  table.reload('LAY-user-manage', {
      url: '/logistics_cablePlan/page', // 后端接口地址
      where: {
        projectId: projectId, // 查询条件
        projectName: projectName,
        cableName: cableName,
        planStatus: planStatus
      }
  });
});

    //事件
    var active = {
      batchdel: function(){
        var checkStatus = table.checkStatus('LAY-user-manage')
                ,checkData = checkStatus.data; //得到选中的数据

        if(checkData.length == 0){
          return layer.msg('请选择数据');
        }


        // 程序走到这里，表示已经有选中要删除的数据了。
        layer.confirm('确定删除吗？',function (){
          var userIds = new Array();
          $.each(checkData,function (index,item){
            userIds.push(item.userId);
          })
          // 提交给后端
          $.ajax({
            url:"/logistics_cablePlan/{id}",
            type:"post",
            data:{id:data.id},
            traditional:true, // 传统序列化
            dataType:"json",
            success:function (res){
              if(res.code == 0){//成功
                layer.msg('已删除');
                table.reload('LAY-user-manage'); //数据刷新
                layer.close(index); //关闭弹层
              }else{
                layer.msg(res.message,{icon: 5});//弹出提示
              }
            }
          })
        })
      }
      ,add: function(){
        layer.open({
          type: 2
          ,title: '新增电缆'
          ,skin: 'layui-layer-win10'
          ,content: 'save.html'
          ,maxmin: true
          ,area: ['480px', '550px']
          ,btn: ['确定', '取消']
          ,yes: function (index,layero){
            var iframeWindow = window['layui-layer-iframe'+ index]
                    ,submitID = 'LAY-user-front-submit'
                    ,submit = layero.find('iframe').contents().find('#'+ submitID);
            //监听提交--隐藏按钮
            iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
              var field = data.field; //获取提交的字段
              // 通过Ajax方式将参数提交到后端--保存数据库中
              $.ajax({
                url:"/admin/save",
                type:"post",
                data:JSON.stringify(field),
                contentType: "application/json;charset=utf-8", //提交参数类型为json格式
                dataType:"json",
                success:function (res){
                  if(res.code == 0){//成功
                    layer.msg(res.message);//弹出提示
                    table.reload('LAY-user-manage'); //数据刷新
                    layer.close(index); //关闭弹层
                  }else{//系统出问题
                    layer.msg(res.message,{icon: 5});//弹出提示
                  }
                }
              })
            });
            submit.trigger('click');
          }

        });
      }
    };

    $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
</script>
</div>
</body>
</html>
